#include "inituserwin.h"
#include "ui_inituserwin.h"
#include <QMessageBox>

InitUserWin::InitUserWin(QWidget *parent) :
	QDialog(parent),
	ui(new Ui::InitUserWin)
{
	ui->setupUi(this);
	ui->lbCodeTip->setVisible(false);
	ui->leUserCode->setVisible(false);
}

InitUserWin::~InitUserWin()
{
	delete ui;
}

void InitUserWin::on_rbNormalUser_clicked()
{
	ui->lbUserTypeTip->setText("普通用户：每天临下班可以填报自己的订餐信息");
	ui->lbCodeTip->setVisible(false);
	ui->leUserCode->setVisible(false);
	ui->buttonBox->setEnabled(true);
}

void InitUserWin::on_rbGroupHeader_clicked()
{
	ui->lbUserTypeTip->setText("组长：除了普通用户的权限，还可以查看组内订餐历史记录");
	ui->lbCodeTip->setVisible(true);
	ui->leUserCode->setVisible(true);
	ui->leUserCode->clear();
	ui->buttonBox->setEnabled(false);
}

void InitUserWin::on_rbDinnerManager_clicked()
{
	ui->lbUserTypeTip->setText("订餐管理员：除了普通用户的权限，还可以查看全部订餐历史记录并可以管理菜单");
	ui->lbCodeTip->setVisible(true);
	ui->leUserCode->setVisible(true);
	ui->leUserCode->clear();
	ui->buttonBox->setEnabled(false);
}

void InitUserWin::on_buttonBox_accepted()
{
	// ok
	int userType = 0;
	if (ui->rbNormalUser->isChecked())
	{
		userType = 1;
	}
	else if (ui->rbGroupHeader->isChecked())
	{
		QString code = ui->leUserCode->text();
		if (code != "135679")
		{
			QMessageBox::critical(this, "错误", "授权码不正确！");
			return;
		}
		userType = 2;
	}
	else
	{
		QString code = ui->leUserCode->text();
		if (code != "357159")
		{
			QMessageBox::critical(this, "错误", "授权码不正确！");
			return;
		}
		userType = 3;
	}
	this->setResult(userType);
	QDialog::accept();
}

void InitUserWin::on_buttonBox_rejected()
{
	// cancel
}

void InitUserWin::on_leUserCode_textChanged(const QString &arg1)
{
	if (arg1.length() > 0)
	{
		ui->buttonBox->setEnabled(true);
	}
	else
	{
		ui->buttonBox->setEnabled(false);
	}
}

void InitUserWin::accept()
{
}
